package com.oscarmovie.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.oscarmovie.model.DescriptionMovie;

public class PlotDaoImpl extends HibernateDaoSupport implements PlotDao {

	public DescriptionMovie load(int id) {
		DescriptionMovie plot = (DescriptionMovie)getSession().load(DescriptionMovie.class, id);
		return plot;
	}
	
	public List<DescriptionMovie> list() {
		Query query = getSession().createQuery("from Plot");
		query.setCacheable(true);
		List<DescriptionMovie> list = (List<DescriptionMovie>)query.list();
		return list;
	}
	public List<DescriptionMovie> listByMovieId(int movieId) {
		Query query = getSession().createQuery("from Plot");
		query.setCacheable(true);
		List<DescriptionMovie> list = (List<DescriptionMovie>)query.list();
		return list;
	}
	
	public List<DescriptionMovie> listByAccountId(int accountId) {
		Query query = getSession().createQuery("from Plot");
		query.setCacheable(true);
		List<DescriptionMovie> list = (List<DescriptionMovie>)query.list();
		return list;
	}
	
	public void save(DescriptionMovie plot) {
		getSession().saveOrUpdate(plot);
	}

	public DescriptionMovie loadByWeiboId(String weiboId) {
		Query query = getSession().createQuery("from Plot plot where plot.weiboId = :weiboId");
		query.setString("weiboId", weiboId);
		DescriptionMovie plot = (DescriptionMovie)query.uniqueResult();
		return plot;
	}
	
}
